package henu.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

import henu.bean.FeedBack;
import henu.bean.User;
import henu.dao.IFeedBackDao;
import henu.dao.IUserDao;
import henu.factory.DaoFactory;

public class CountAction extends ActionSupport{
	
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		HttpServletRequest request = ServletActionContext.getRequest();
		String action=request.getParameter("action");
		FeedBack back=new FeedBack();
		IFeedBackDao dao=DaoFactory.createFeedBackDao();
		//此入口的作用是从数据库中get所有记录的数据，展示到面板中
		if(action.equals("openTeacher")){
			HttpSession session=request.getSession();
			List<FeedBack> backs=null;
			
			backs=dao.getAll();
			if(backs!=null)
			{
			
				session.setAttribute("backs",backs);
				return "TEACHER";
			}
			else{
				return ERROR;
			}
			
		}
		if(action.equals("openoWeek")){
			HttpSession session=request.getSession();
			List<FeedBack> backs=null;
			
			backs=dao.getAll();
			if(backs!=null)
			{
			
				session.setAttribute("backs",backs);
				return "WEEK";
			}
			else{
				return ERROR;
			}
			
		}
		if(action.equals("openCourse")){
			HttpSession session=request.getSession();
			List<FeedBack> backs=null;
			
			backs=dao.getAll();
			if(backs!=null)
			{
			
				session.setAttribute("backs",backs);
				return "COURSE";
			}
			else{
				return ERROR;
			}
			
		}
		
		if(action.equals("getAll")){
			List<FeedBack> lists = null;
			request = ServletActionContext.getRequest();
			lists = DaoFactory.createFeedBackDao().getAll();
			request.getSession().setAttribute("fbs", lists);
			return "getAll";
		}
		
		if(action.equals("querry")){
		 String province=request.getParameter("province");
		 String value=request.getParameter("value");
		 System.out.println(province);
		 System.out.println(value);
			HttpSession session=request.getSession();
			List<FeedBack> backs=null;
			backs=dao.select(province,value);
			session.setAttribute("backs",backs);
			if(province.equals("teacher"))
			{
				return "TEACHER";
			}
			if(province.equals("week"))
			{
				return "WEEK";
			}
			if(province.equals("course"))
			{
				return "COURSE";
			}
				
		}
		return super.execute();
	}
}
